package com.yufubao.test;

import com.alibaba.fastjson.JSON;
import com.yufubao.framework.builder.es.RequestOptionsBuilder;
import com.yufubao.strat.YufubaoStratApplication;
import lombok.Data;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.xcontent.XContentType;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.IOException;
import java.util.Date;

/**
 * @author 张一恒
 * @version 1.0
 * @description:
 * @date 2024/8/26 15:37
 */
@SpringBootTest(classes = YufubaoStratApplication.class)
public class Yufubaotest {

    @Autowired
    private RestHighLevelClient restHighLevelClient;




    //新建index 存入数据
    @Test
    void newIndex() throws IOException {
        IndexRequest indexRequest = new IndexRequest("users");
        User user = new User();
        user.setName("zhangsan");
        user.setAge(20);
        user.setDay(new Date());

        indexRequest.source(JSON.toJSONString(user), XContentType.JSON);

        IndexResponse indexed = restHighLevelClient.index(indexRequest, RequestOptionsBuilder.COMMON_OPTIONS);

        System.out.println(indexed);

    }

    @Data
    static class User {
        private String name;
        private Integer age;
        private Date day;
    }

    @Test
    public void test1() throws IOException {
        Byte i = 1;
        System.out.println(i);
    }
}
